package io;

import java.io.*;

/*
 * @author zzr
 * @date: 2025/04/13  16:03
 * @description:
 */
public class IODemo7 {
    public static void main(String[] args) throws IOException {

        try (InputStream inputStream = new FileInputStream("./test.txt")) {

            StringBuffer content = new StringBuffer();
            // 读文件 也不知道文件有多少字节，使用 while 来完成
            while (true) {

                // 也可以一次读若干个字节
                byte[] buffer = new byte[1024];
                int n = inputStream.read(buffer);
                if (-1 == n) {
                    //文件读取完毕
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.printf("%x ", buffer[i]);
                }
            }
        }
    }
}
